﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace BlakeAndMattGame
{
    /// <summary>
    /// The moving objects on the screen
    /// </summary>
    class GameSprite
    {

        public Vector2 speed;
        public Vector2 position;
        public Texture2D texture;

        public GameSprite(Vector2 position, Vector2 speed, Texture2D texture)
        {
            this.speed = speed;
            this.position = position;
            this.texture = texture;   
        }

        public void Draw(SpriteBatch spriteBatch)
        {
            spriteBatch.Draw(texture, position, Color.White);
        }

        public Rectangle BoundingBox
        {
            get
            {
                return new Rectangle((int)position.X, (int)position.Y, texture.Width, texture.Height);
            }
        }

        public void Move(GraphicsDeviceManager graphics, GameTime gameTime)
        {
            int MaxX = graphics.GraphicsDevice.Viewport.Width - texture.Width;
            int MinX = 0;
            int MaxY = graphics.GraphicsDevice.Viewport.Height - texture.Height;
            int MinY = 0;
            
            position += speed * (float)gameTime.ElapsedGameTime.TotalSeconds;

            //Console.WriteLine(position.X + " " + position.Y + " (" + gameWidth + ", " + gameHeight + ")");

            if (position.X > MaxX)
            {
                speed.X *= -1;
                position.X = MaxX;
            }

            else if (position.X < MinX)
            {
                speed.X *= -1;
                position.X = MinX;
            }

            if (position.Y > MaxY)
            {
                speed.Y *= -1;
                position.Y = MaxY;
            }

            else if (position.Y < MinY)
            {
                speed.Y *= -1;
                position.Y = MinY;
            }
        }


    }
}
